package 笔试.thread;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) {
        int studentNum = 6;
        CountDownLatch countDownLatch = new CountDownLatch(studentNum);
        for (int i = 0; i < studentNum; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "同学离开了");
                countDownLatch.countDown();
            }).start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "要关门了,此时教室已经没人了~");
    }
}
